#!/usr/bin/env python
import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
from google.appengine.dist import use_library
use_library('django', '1.2')
from google.appengine.api import users
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext.webapp import template
from model import LectureM
from model import GeneralM
from model import PostClassM
import datetime

class stats_page(webapp.RequestHandler):
    def get(self):
        user = users.get_current_user()
        if user:
            lectureKey = self.request.get('lectureKey')
            if lectureKey:
                lecture = LectureM.getLectureByKey(lectureKey)
                viewVals = GeneralM.getViewVals()
                viewVals['lecture'] = LectureM.getLectureByKey(lectureKey)
                viewVals['lectureKey'] = lectureKey
                viewVals['postClasses'] = PostClassM.getPostClassList(lecture)
#                viewVals['dates'] = map(getDate, PostClassM.getPostClassList(lecture))
#                viewVals['topic_stats'] = PostClassM.getTopicsStats(postClassKey)
#                viewVals['question_stats'] = PostClassM.getQuestionsStats(postClassKey)
#                viewVals['classID'] = ClassM.getClassID(key)
                self.response.out.write(template.render('view/lecture_stats.djhtml', viewVals))
            else:
                self.redirect("/allCourses")
        else:
            self.redirect("/login")

application = webapp.WSGIApplication([(r'.*', stats_page)],debug=True)

def getDate(postClass):
    dt = postClass.date;
    return datetime.date(dt.year, dt.month, dt.day)

def main():
    run_wsgi_app(application)
    
if __name__ == '__main__':
    main()